<?php

if(!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * This class finds correspoding discounts for room
 *
 * Must have serch inputs are
 *
 * Room: Room ID,
 * Child Age: childAge
 *
 * It automaticly finds corresponding discount rule
 *
 * @author ivankukic
 */
class discount_finder
{

    private $room_id;
    private $childage=array();
    private $nradults;

    public function __construct()
    {
        $this->CI=&get_instance();
        $this->CI->load->model("rooms_has_discounts_model");
        $this->CI->load->model("discounts_model");

    }

    public function getRoom_id()
    {
        return $this->room_id;

    }

    public function setRoom_id($room_id)
    {
        $this->room_id=$room_id;

    }

    public function getChildAge()
    {
        return $this->childage; //return array

    }

    public function setChildAge($age)
    {
        $this->childage=(int) $age;

    }
    public function setNradults($nradults)
    {
        $this->nradults=(int) $nradults;

    }

    public function getNradults()
    {
        return $this->nradults;

    }


    // return discount in percent as intigrer, 0 if no discount
    public function find_discount()
    {
        // find corresponding discount
        $discount_ID=$this->CI->rooms_has_discounts_model->find_discount_id($this->room_id);
        if($discount_ID == 0)
            return 0;

        // TODO here we should pass nr_adults arg, and in discounts model have method that will act as
        // find_discount_rule but should query results based on nr_adults too
        // method name find_discount_rule_nr_adults($discount_ID, $this->childage, $this->nr_adults)
        // $discount=$this->CI->discounts_model->find_discount_rule($discount_ID, $this->childage);
        $discount=$this->CI->discounts_model->find_discount_rule_nr_adults($discount_ID, $this->childage, $this->nradults);
        return (int) $discount;

    }

}

?>
